home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kleo / dn.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-08-19  |  3.9 KB  |  143 lines

  1. /*
  2.     dn.h
  3.  
  4.     This file is part of libkleopatra, the KDE keymanagement library
  5.     Copyright (c) 2004 KlarΣlvdalens Datakonsult AB
  6.  
  7.     Libkleopatra is free software; you can redistribute it and/or
  8.     modify it under the terms of the GNU General Public License as
  9.     published by the Free Software Foundation; either version 2 of the
  10.     License, or (at your option) any later version.
  11.  
  12.     Libkleopatra is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.     General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  
  21.     In addition, as a special exception, the copyright holders give
  22.     permission to link the code of this program with any edition of
  23.     the Qt library by Trolltech AS, Norway (or with modified versions
  24.     of Qt that use the same license as Qt), and distribute linked
  25.     combinations including the two.  You must obey the GNU General
  26.     Public License in all respects for all of the code used other than
  27.     Qt.  If you modify this file, you may extend this exception to
  28.     your version of the file, but you are not obligated to do so.  If
  29.     you do not wish to do so, delete this exception statement from
  30.     your version.
  31. */
  32.  
  33. #ifndef __KLEO_DN_H__
  34. #define __KLEO_DN_H__
  35.  
  36. #include <qstring.h>
  37. #include <qvaluevector.h>
  38. #include <kdepimmacros.h>
  39.  
  40. class QStringList;
  41. class QWidget;
  42.  
  43. namespace Kleo {
  44.   class DNAttributeOrderConfigWidget;
  45. }
  46.  
  47. namespace Kleo {
  48.  
  49.   /**
  50.      @short DN Attribute mapper
  51.   */
  52.   class KDE_EXPORT DNAttributeMapper {
  53.     DNAttributeMapper();
  54.     ~DNAttributeMapper();
  55.   public:
  56.     static const DNAttributeMapper * instance();
  57.  
  58.     QString name2label( const QString & s ) const;
  59.     QStringList names() const;
  60.  
  61.     const QStringList & attributeOrder() const;
  62.  
  63.     void setAttributeOrder( const QStringList & order );
  64.  
  65.     DNAttributeOrderConfigWidget * configWidget( QWidget * parent=0, const char * name=0 ) const;
  66.  
  67.   private:
  68.     class Private;
  69.     Private * d;
  70.     static DNAttributeMapper * mSelf;
  71.   };
  72.  
  73.   /**
  74.      @short DN parser and reorderer
  75.   */
  76.   class KDE_EXPORT DN  {
  77.   public:
  78.     class Attribute;
  79.     typedef QValueVector<Attribute> AttributeList;
  80.     typedef AttributeList::const_iterator const_iterator;
  81.  
  82.     DN();
  83.     DN( const QString & dn );
  84.     DN( const char * utf8DN );
  85.     DN( const DN & other );
  86.     ~DN();
  87.  
  88.     const DN & operator=( const DN & other );
  89.  
  90.     /** @return the value in rfc-2253-escaped form */
  91.     static QString escape( const QString & value );
  92.  
  93.     /** @return the DN in a reordered form, according to the settings in
  94.     the [DN] group of the application's config file */
  95.     QString prettyDN() const;
  96.     /** @return the DN in the original form */
  97.     QString dn() const;
  98.  
  99.     QString operator[]( const QString & attr ) const;
  100.  
  101.     void append( const Attribute & attr );
  102.  
  103.     const_iterator begin() const;
  104.     const_iterator end() const;
  105.  
  106.   private:
  107.     void detach();
  108.   private:
  109.     class Private;
  110.     Private * d;
  111.   };
  112.  
  113.   class KDE_EXPORT DN::Attribute {
  114.   public:
  115.     typedef DN::AttributeList List;
  116.  
  117.     Attribute( const QString & name=QString::null, const QString & value=QString::null )
  118.       : mName( name.upper() ), mValue( value ) {}
  119.     Attribute( const Attribute & other )
  120.       : mName( other.name() ), mValue( other.value() ) {}
  121.  
  122.     const Attribute & operator=( const Attribute & other ) {
  123.       if ( this != &other ) {
  124.     mName = other.name();
  125.     mValue = other.value();
  126.       }
  127.       return *this;
  128.     }
  129.  
  130.     const QString & name() const { return mName; }
  131.     const QString & value() const { return mValue; }
  132.  
  133.     void setValue( const QString & value ) { mValue = value; }
  134.     
  135.   private:
  136.     QString mName;
  137.     QString mValue;
  138.   };
  139.  
  140. }
  141.  
  142. #endif // __KLEO_DN_H__
  143.